package com.maven.front.service.sysuser;

import com.maven.front.bean.Result;
import com.maven.front.bean.SysUser;
import com.maven.front.mapper.SysUserMapper;
import com.sun.org.apache.regexp.internal.RE;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class SysUserService {

    @Resource
    private SysUserMapper sysUserMapper;

    public List<SysUser> list(){
        List<SysUser> list=sysUserMapper.select();
        //判断集合是否为空
        if (CollectionUtils.isEmpty(list)){
            return null;
        }else {
            return list;
        }
    }

    //根据id查询,返回页面
    public Result getid(String id){
        String [] arr = id.split(",");
        List<SysUser> list = new ArrayList<>();
        for (int i=0; i<arr.length; i++){
            log.info(arr[i]);
            SysUser sysUser = new SysUser();
            if(arr[i]!=null){
                sysUser =sysUserMapper.getid(Integer.valueOf(arr[i]));
                list.add(sysUser);
            }
        }
        if (CollectionUtils.isEmpty(list)){
            return new Result(10005, "查询失败！", null);
        } else {
            return new Result(200, "查询成功！", list);
        }
    }


    public SysUser selectByPrimaryKey(Integer id){
        return sysUserMapper.selectByPrimaryKey(id);
    }




}
